package services

import (
	"ctrip-travel/rpc/global"
	"ctrip-travel/rpc/models/dao"
)

func CreateUser(user dao.User) error {
	return global.Db.Create(&user).Error
}

func GetUserInfo(name string) (user dao.User, err error) {
	err = global.Db.Where("name = ?", name).First(&user).Error
	return user, err
}

func CreateVote(vote dao.Vote) error {
	return global.Db.Create(&vote).Error
}

func CreateOrder(order dao.Order) error {
	return global.Db.Create(&order).Error
}

func QueryVote(state int) (vote []*dao.Vote, err error) {
	err = global.Db.Where("state = ?", state).First(&vote).Error
	return vote, err
}

func CreateBuyTickets(tickets dao.BuyTickets) error {
	return global.Db.Create(&tickets).Error
}

func OrderList(userId int) (list []*dao.Order, err error) {
	err = global.Db.Where("user_id = ?", userId).First(&list).Error
	return list, err
}
